package com.jo.util;

import java.util.LinkedHashSet;
import java.util.Set;

/**
 * class类的工具类
 * @author Jo
 * @date 2018/1/26
 */
public class ClassUtils {

    /**
     * 获取类及其所有父类的接口的class对象
     * @param clazz
     * @return
     */
    public static Set<Class<?>> getAllInterfacesClassAsSet(Class<?> clazz){
        Set<Class<?>> interfaces = new LinkedHashSet<>();
        while (clazz != null) {
            Class<?>[] ifcs = clazz.getInterfaces();
            for (Class<?> ifc : ifcs) {
                interfaces.addAll(getAllInterfacesClassAsSet(ifc));
            }
            clazz = clazz.getSuperclass();
        }
        return interfaces;
    }
}
